<style>
.moad_inputbox{ margin-bottom:15px; position:relative;}
.moad_inputbox input{ border:none;box-shadow:0 0 3px #ddd; border-radius:4px; text-align:right;font-family: 微软雅黑;font-size: 25px;font-weight: bold;color: rgb(102, 102, 102); width:100%; padding:5px 52px 5px 0}
.moad_inputbox span{ position:absolute; right:15px; top:10px; line-height:25px;font-size:25px;color:#CCC}
.page_paybox{background:#DDD;}
.page_paybox .pp_left{ width:370px;padding:15px 10px 15px 15px; float:left; background:#FFF;}
.page_paybox .pp_middle{width:70px; margin:0 4px;float:left; background:#FFF}
.page_paybox .pp_right{ width:360px;display:inline-block; background:#FFF;float:right;border-left:5px solid #EEE; padding-right:10px;}
.page_paybox .pp_left ul{ width:100%; display:block}
.page_paybox .pp_left ul li{ border-bottom:1px solid #EEE; padding:0 0; width:100%; display:-webkit-flex;display:flex; position:relative;}
.page_paybox .pp_left ul li label{ font-size:17px; color:#999;font-weight:normal;width:110px; line-height:36px;}
.page_paybox .pp_left ul li label b{ font-size:12px; font-weight:normal}
.page_paybox .pp_left ul li input{ background:none; border:none; text-align:right; padding:0 10px; margin:; width:200px; font-size:29px; height:36px}
.page_paybox .pp_left ul li span{width:30px; display:block; margin-top:10px; text-align:right; color:#999}
.page_paybox .pp_left ul li.dis input{width:100px; color:#F66;}
.ppl_searchbox{ margin:10px 0; background:#f3f3f3; padding:5px; position:relative;}
.ppl_searchbox input{ background:none; border:none; font-size:14px; line-height:30px; height:30px; padding-left:30px; width:100%;}
.ppl_searchbox span{ display:inline-block; position:absolute; top:10px; left:10px; font-size:20px; color:#999}
.ppl_searchbox button{ display:inline-block; position:absolute; top:10px; right:10px; border: none; background: none;}
.ppl_userbox{ background:#288ad6;color:#FFF; padding:10px; margin-bottom:10px;}
.ppl_userinfo{ padding-left:10px;}
.ppl_userinfo div:first-child{ margin-bottom:5px;}
.ppl_userlevel{ }
.ppl_userbox a{ margin-top:25px;display:inline-block; padding:3px 8px; background:rgba(255,255,255,0.3); color:#FFF; border-radius:4px; font-size:80%}
.ppl_userdetail div[class^=col]{ padding:0; text-align:center; margin:0}
.ppl_userdetail div[class^=col] p:last-child{ color:#F66}
.ppm_btngroup{ padding:10px 0;}
.ppm_btngroup button{ width:100%; border:1px solid #C9C9C9; background:#FFF; display:block; text-align:center; padding:10px 0; margin-bottom:10px;-webkit-transition:all 0.3s; transition:all 0.3s;}
.ppm_btngroup button:hover{ border:1px solid #009688; background:#009688; color:#FFF;}
.ppr_keybord{ padding:5px 5px 5px 15px;}
.ppr_keybord td{height:40px;line-height:40px;background: #fff;text-align: center;color: #31c17b;cursor: pointer; font-size:20px; font-weight:bold}
.ppr_keybord td.red{color:#F66;}
.ppr_btngroup {padding:5px 5px 5px 15px; margin-bottom:10px}
.ppr_btngroup .layui-btn-group{ display:block;}
.ppr_btngroup .layui-btn-group button{ width:25%;height:56px; line-height:56px;}
.ppr_paybtngroup{position:relative;}
.ppr_paybtngroup table{ width:100%; border:1px solid #CCC;}
.ppr_paybtngroup table tr td{ border-right:1px solid #CCC; border-bottom:1px solid #CCC; text-align:center; height:56px; max-width:81.25px; cursor:pointer}
.ppr_paybtngroup table tr td:last-child{ border-right:none;}
.ppr_paybtngroup td.isselect{background:#31c17b;color:#FFF}
.ppr_paybtngroup td.ischeck{background:#FF5722;color:#FFF}
.ppr_paybtngroup button{ height:56px; line-height:56px;}
.btn_paysure{background:#FFB800; color:#FFF;}
.btn_paysure div{ font-size:60%;}
.ppr_btndiscount div[class^='layui-col']{ text-align:center; border:1px solid #CCC; line-height:56px; cursor:pointer;}
.ppr_btndiscount div[class^='layui-col']:nth-child(2){ border-left:none;border-right:none;}
.ppr_btndiscount div[class^='layui-col'].isselect{background:#31c17b; color:#FFF;}
.ppl_userlevel{ background:rgba(255,255,255,0.5); border-radius:4px; display:inline-block; padding:2px 3px; font-size:80%}
.ppr_paybtnc .isselect{ background:#31c17b;color:#FFF}
.ppr_ctrl button.isselect{color:#288ad6}
</style>
<div class="modal_paycounter" index style="display:none;">
  <div class="page_paybox">
    <div class="pp_left">
      <form class="layui-form" id="form_paycounter" name="form_paycounter" action="">
        <ul>
          <li>
            <label>订单</label>
            <input type="text" value="0" readonly id="ppl_input_orderfee" namn="ppl_input_orderfee"/>
          </li>
          <li class="dis"> 
            <!--0无优惠,1系统满减，2手动折扣，3优惠券-->
            <label id="ppl_dtype" type="0" default="">优惠</label>
            <input type="text" value="100%" readonly  id="ppl_input_discount" namn="ppl_input_discount"/>
            <input type="text" value="0" readonly  id="ppl_input_coupon" namn="ppl_input_coupon"/>
            <span onclick="fun_ppRemove(2)"><i class="fa fa-remove-sign"></i></span> </li>
          <li>
            <label>应收</label>
            <input type="text" value="0" readonly  id="ppl_input_totalfee" namn="ppl_input_totalfee"/>
          </li>
          <li>
            <label style="color:#ff6a00" id="ppl_ptype">现金</label>
            <input type="text" style="color:#ff6a00" value="0" maxlength="8" isselect="true" id="ppl_input_paidfee" onfocus='fun_changepaybox(this)' namn="ppl_input_paidfee" onkeyup="fun_checkpaypress(this)"/>
            <span onclick="fun_ppRemove(3)"><i class="fa fa-remove-sign"></i></span> 
          </li>
          <li>
            <label style="color:#ff6a00" id="ppl_ptype2">待收</label>
            <input type="text" style="color:#ff6a00" value="0" maxlength="8" onfocus='fun_changepaybox(this)' readonly namn="ppl_input_paidfee2" id="ppl_input_paidfee2" onkeyup="fun_checkpaypress(this)"/>
            <span onclick="fun_ppRemove(5)"><i class="fa fa-remove-sign"></i></span> 
          </li>
          <li>
            <label>找零</label>
            <input type="text" value="0" readonly  id="ppl_input_change" namn="ppl_input_change"/>
          </li>
          <li>
            <label>备注</label>
            <input type="text" value=""  id="ppl_input_remark" namn="ppl_input_remark" onfocus='fun_changepaybox(this)' />
            <span onclick="fun_ppRemove(4)"><i class="fa fa-remove-sign"></i></span> </li>
        </ul>
        <input type="hidden" name="ppl_paytype" id="ppl_paytype" value="2" />
        <input type="hidden" name="ppl_paytype2" id="ppl_paytype2" value="-1" />
        <input type="hidden" name="ppl_memberid" id="ppl_memberid"  />
        <input type="hidden" name="ppl_code" id="ppl_code" />
        <input type="hidden" name="ppl_qrcode" id="ppl_qrcode" />
        <input type="hidden" name="ppl_qrcode" id="ppl_paycode" />
        <input type="hidden" name="ppl_orderid" id="ppl_orderid" />
        <input type="hidden" name="pp_coupontype" id="pp_coupontype" />
        <input type="hidden" name="pp_couponno" id="pp_couponno" />
        
      </form>
      <form class="layui-form" onsubmit="pp_searchTxtForm();return false;" action="">
        <div class="ppl_searchbox">
          <input type="text" onfocus='fun_changepaybox(this)' id="pp_searchTxt" placeholder="请输入会员卡号/电话号码"/>
          <span><i class="fa fa-search"></i></span>
			<button type="submit">搜索</button>
		</div>

      </form>
      <div class="ppl_userbox ">
        <div class="row">
          <div class="col-xs-2"><img id="ppl_txtheadimg" src="" onerror="this.src='{MODULE_URL}template/resources/img/002.png';" style="width:48px;height:48px;border-radius:100%" /></div>
          <div class="col-xs-7">
            <div class="ppl_userinfo">
              <div><span id="ppl_txtrealname"></span> <span class="ppl_userlevel" id="ppl_txtlevel"></span></div>
              <div><span id="ppl_txtmobile"></span> <span id="ppl_txtdiscount"></span></div>
            </div>
          </div>
          <div class="col-xs-3"> <a href="javascript:pp_searchTxtChargebtn()">充值</a> </div>
        </div>
      </div>
      <div class="ppl_userdetail">
        <div class="row">
          <div class="col-xs-3">
            <p>积分</p>
            <p id="ppl_txtcredit">&nbsp;</p>
          </div>
          <div class="col-xs-3">
            <p>余额</p>
            <p id="ppl_txtcash"></p>
          </div>
          <div class="col-xs-3">
            <p>累计消费</p>
            <p id="ppl_txtcost"></p>
          </div>
          <div class="col-xs-3">
            <p>生日</p>
            <p id="ppl_txtbirdday"></p>
          </div>
        </div>
      </div>
      <div class="layui-form" id="isprintform" style="margin-top:10px">
      	<input type="checkbox" name="like[write]" checked  title="打印小票" />
      </div>
    </div>
    <div class="pp_right">
      <div class="ppr_keybord">
        <table class="layui-table">
          <tbody>
            <tr>
              <td style="width:25%" onclick="fun_btncount(7)">7</td>
              <td style="width:25%" onclick="fun_btncount(8)">8</td>
              <td style="width:25%" onclick="fun_btncount(9)">9</td>
              <td style="width:25%" onclick="fun_btncount(20)" class="red">20</td>
            </tr>
            <tr>
              <td onclick="fun_btncount(4)">4</td>
              <td onclick="fun_btncount(5)">5</td>
              <td onclick="fun_btncount(6)">6</td>
              <td class="red" onclick="fun_btncount(50)">50</td>
            </tr>
            <tr>
              <td onclick="fun_btncount(1)">1</td>
              <td onclick="fun_btncount(2)">2</td>
              <td onclick="fun_btncount(3)">3</td>
              <td class="red" onclick="fun_btncount(100)">100</td>
            </tr>
            <tr>
              <td onclick="fun_btncount(0)">0</td>
              <td onclick="fun_btncount('.')">.</td>
              <td onclick="fun_btncount('C')">C</td>
                <td class="red"  onclick="fun_inputAll()">全付</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="ppr_btngroup ppr_btndiscount">
        <div class="layui-row">
          <div class="layui-col-xs4 counterCoupon" onclick="fun_counterCoupon(1)">手动改价</div>
          <div class="layui-col-xs4 counterCoupon" onclick="fun_counterCoupon(2)">手动折扣</div>
          <div class="layui-col-xs4 counterCoupon" onclick="fun_counterCoupon(3)">微信卡券</div>
        </div>
      </div>
      <div class="ppr_btngroup ppr_paybtngroup">
      <table >
          <tbody>
            <tr>
              <td style="width:25%"  class="pprbtn isselect" paytype="2" onclick="fun_selectPaytype(2)"><div><i class="fa fa-ok"></i></div>现金</td>
              <td style="width:25%"  class="pprbtn" paytype="3" onclick="fun_selectPaytype(3)">银行卡</td>
              <td style="width:25%"  class="pprbtn" paytype="4" onclick="fun_selectPaytype(4)">会员卡</td>
              <td style="width:25%" onclick="fun_grouppay(this)" id="isgrouppay" isgrouppay="0">组合支付</td>
            </tr>
            <tr>
                {if !$cfg["isymf"] && !$cfg["isbank"] && !$cfg["appid"] && !$shop["appid"]}
                <td style="width:25%"  class="pprbtn" paytype="0">-</td>
                {else}
                <td style="width:25%"  class="pprbtn" paytype="0" onclick="fun_selectPaytype(0)">微信</td>
                {/if}
                {if !$cfg["isymf"] && !$cfg["isbank"] && !$cfg["app_id"] && !$shop["app_id"]}
                <td style="width:25%"  class="pprbtn" paytype="1">-</td>
                {else}
              <td style="width:25%"  class="pprbtn" paytype="1" onclick="fun_selectPaytype(1)">支付宝</td>
                {/if}
              {if $shop['custom_pay1_status']}
              <td style="width:25%"  class="pprbtn" paytype="5" onclick="fun_selectPaytype(5)">{$shop['custom_pay1']}</td>
              {else}
              <td style="width:25%"  class="pprbtn">-</td>
              {/if}
              <td rowspan="2" style="width:25%" class="btn_paysure" onclick="fun_payPost();">确认
          <div>结算完成</div></td>
            </tr>
            <tr>
              {if $shop['custom_pay2_status']}
              <td style="width:25%" class="pprbtn" paytype="6" onclick="fun_selectPaytype(6)">{$shop['custom_pay2']}</td>
              {else}
              <td style="width:25%"  class="pprbtn">-</td>
              {/if}
              {if $shop['custom_pay3_status']}
              <td style="width:25%" class="pprbtn" paytype="7" onclick="fun_selectPaytype(7)">{$shop['custom_pay3']}</td>
              {else}
              <td style="width:25%"  class="pprbtn">-</td>
              {/if}
              {if $shop['custom_pay4_status']}
              <td style="width:25%" class="pprbtn" paytype="8" onclick="fun_selectPaytype(8)">{$shop['custom_pay4']}</td>
              {else}
              <td style="width:25%"  class="pprbtn">-</td>
              {/if}
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

<div class="modal_inputbox" index style="display:none;">
<form index="" class="layui-form" action="" style="padding:15px">
  <Div class="text-center" id="modal_inputboximg" style="margin:20px 0;"><img src="{MODULE_URL}template/resources/img/scaner.png" /></Div>
  <div class="layui-form-item">
    <input type="text" name="modal_inputbox" id="modal_inputbox" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
  </div>
  <div style="padding:10px; text-align:center" class="help-block"></div>
  <div class="row">
    <div class="col-md-12"><Div class="text-center"> <button class="layui-btn" id="modal_inputboxbtn" type="submit" >提交</button></Div></Div>
  </div>
</form>
</div>
<script>
    function fun_checkpaypress(obj){
        var tempval=$(obj).val();
        var tempval=tempval.replace(/[^\d.]/g,'');
        tempval=tempval.replace(/\b(0+)/gi,"");
        if(isNaN(parseFloat(tempval)))tempval=0;
        $(obj).val(tempval);
        fun_paycount();
    }
var payTypeAry=[2];
function fun_btncount(num){
    var target=$(".page_paybox input[isselect='true']");
    txt="#"+target.attr("id");
    //alert(txt);
	if(parseInt(num)>10){
		target.val(num);
		fun_paycount();
	}else if(num=="D"){
		var temp=$("#ppl_input_totalfee").val().split(".");
		$("#ppl_input_totalfee").val(temp[0]+".00");
		fun_paycount();
		return false;
	}else{
		Counter(num,txt);
		fun_paycount();
	}
}
function fun_changepaybox(obj){
    $(".page_paybox input").removeAttr("isselect");
    $(obj).attr("isselect",true);
}
function fun_startPay(orderid){
	var index2=layer.load(1, {shade: [0.1,'#fff']})
	layer.open({
		type:1,
		title:0,
		shade: [0.1,'#fff'],
		area:'760px',
		skin: 'layui-layer-rim',
		content:$(".modal_paycounter").show(),
		success: function(layero, index){
			payTypeAry=[];
			$(".pprbtn[paytype='2']").click();
			layui.use(['form'], function(){
				var form = layui.form;
				form.render();
			});
			$("#ppl_orderid").val(orderid);
			$.post("{php echo $this->createMobileUrl('index',array('op'=>'getorder'))}",{orderid:orderid},function(returnstr){
				layer.close(index2);
				console.log(returnstr);
				var result=eval("("+returnstr+")");
				if(result.success){
					var trade=result.trade;
					if(parseInt(trade.ispay)==1){
						layer.close(index);
						layer.msg("该订单已付款",{icon:2,time:1800});
						return;
					}
					if(!parseInt(trade.order_fee)){
						layer.close(index);
						layer.msg("请先选择商品",{icon:2,time:1800});
						return;
					}
					var orderfee=parseInt(trade.order_fee)*0.01;

					$("#ppl_input_orderfee").val(orderfee.toFixed(2));
					if(result.market){
						var market=result.market;
						$("#ppl_dtype").attr("type",1).attr("default",market.coupon).text("系统优惠");
						$("#pp_coupontype").attr("mid",market.mid).val(1);
						var disount=fee2num(market.coupon);
						$("#ppl_input_coupon").val(disount);
						$("#ppl_input_discount").val(parseInt(((orderfee-parseFloat(disount))/orderfee)*100)+"%");
					}
					if(parseInt(trade.memberno)){
						$("#pp_searchTxt").val(trade.membercardno);
						pp_searchTxtForm();
					}else{
						fun_paycount();
					}
					
				}else{
					layer.msg(result.msg,{icon:2,time:2000});
					return;
				}
				
			});
            $('#ppl_input_paidfee').focus();

		},
		end:function(){
			$("#ppl_input_orderfee").val('0.00');
			$("#ppl_input_teafee").val('0.00');
			$("#ppl_dtype").val(0);
			$("#ppl_dtype").attr("type","0").attr("default","");
			$("#ppl_input_discount").val('100%');
			$("#ppl_input_coupon").val('0.00');
			$("#ppl_input_totalfee").val('0.00');
			$("#ppl_input_paidfee").val('0');
			$("#ppl_input_paidfee2").val('0');
			$("#ppl_ptype").val(0);
			$("#ppl_ptype2").val("-1");
			$("#ppl_input_change").val('0.00');
			$("#ppl_ptype").text("现金");
			$("#ppl_input_remark").val('');
			$("#ppl_paytype").val(2);
			$("#ppl_memberid").val('');
			$("#ppl_code").val('');
			$("#ppl_paycode").val('');
            $("#ppl_qrcode").val('');
			$("#ppl_orderid").val('');
			$("#pp_coupontype").val('');
			$("#pp_couponno").val('');
			$("#pp_searchTxt").val('');
			$("#ppl_txtrealname").text('');
			$("#ppl_txtmobile").text('');
			$("#ppl_txtlevel").text('');
			$("#ppl_txtdiscount").text('');
			$("#ppl_txtcredit").text('');
			$("#ppl_txtcash").text('');
			$("#ppl_txtcost").text('');
			$("#ppl_txtbirdday").text('');
			$(".ppr_btndiscount button").removeClass("isselect");
			$(".pprbtn").removeClass("isselect").find("div").remove();
			$(".modal_paycounter").hide();
			$("#isgrouppay").removeAttr("isgrouppay").removeClass("ischeck").text("组合支付");
		}
	});
}

function fun_counterCoupon(type){
	var orderfee=parseFloat($("#ppl_input_orderfee").val());
	var totalfee=parseFloat($("#ppl_input_totalfee").val());
	var minDiscount=parseInt("{$shop['mindiscount']}");
	switch(type){
		case 1:
			fun_modal({
				"title":"修改价格（0~"+orderfee+")",
				"type":true,
				"success":function(inputval,index){
					if(isNaN(inputval)){
						layer.msg("请输入数字",{icon:2,time:2000});
						return;
					}
					if(parseFloat(inputval)>orderfee){
						layer.msg("优惠金额不能大于订单金额",{icon:2,time:2000});
						return;
					}
					if(minDiscount>0){
						if(parseInt((parseFloat(inputval)/str2num(orderfee)))<minDiscount){
							layer.msg("优惠金额不能大于"+minDiscount+"%",{icon:2,time:2000});
							return;
						}
					}
					layer.close(index);
					var tempfee=parseFloat(inputval);
					var disount=orderfee-tempfee;
					$("#ppl_input_coupon").val(disount);
					$("#ppl_input_discount").val(parseInt((parseFloat(inputval)/orderfee)*100)+"%");
					$(".counterCoupon").eq(0).addClass("isselect").siblings().removeClass("isselect");
					$("#ppl_dtype").attr("type",1);
					$("#ppl_dtype").text("手动折扣");
					$("#pp_coupontype").val(1);
					fun_paycount();

				}
			});
		break;
		case 2:
			fun_modal({
				"title":"修改折扣（0~100)",
				"type":true,
				"success":function(inputval,index){
					if(isNaN(inputval)){
						layer.msg("请输入0-100之间的数字",{icon:2,time:2000});
						return;
					}
					if(minDiscount>0){
						if(parseInt(inputval)<minDiscount){
							layer.msg("优惠金额不能小于"+minDiscount+"%",{icon:2,time:2000});
							return;
						}
					}
					layer.close(index);
					var tempdis=100-parseInt(inputval);
					var disount=(orderfee*tempdis*0.01).toFixed(2);
					$("#ppl_input_coupon").val(disount);
					$("#ppl_input_discount").val(parseInt(inputval)+"%");
					$(".counterCoupon").eq(1).addClass("isselect").siblings().removeClass("isselect");
					$("#ppl_dtype").attr("type",1).text("手动折扣");
					fun_paycount();

				}
			});
		break;
		case 3:
			layer.open({
				type:1,
				title:"使用微信优惠券",
				shade: [0.1,'#fff'],
				area:'300px',
				skin: 'layui-layer-rim',
				content:$(".modal_inputbox").show(),
				success: function(layero, index){
					$(document).unbind("keydown");
					$("#modal_inputboximg").show();
					$("#modal_inputboximg .help-block").text("请让客户打开卡包的中的优惠券");
					$("#modal_inputbox").val('').attr("placeholder","请扫描/输入卡券号码");
					$("#modal_inputbox").focus();
					$("#modal_inputboxbtn").bind("click",function(){
						var index2=layer.load(1, {shade: [0.1,'#fff']});
						var cardno=$("#modal_inputbox").val();
						$.post("{php echo $this->createMobileUrl('index',array('op'=>'checkcoupon'))}",{code:cardno},function(returnstr){
							layer.close(index2);
							layer.close(index);
							console.log(returnstr);
							var result=eval("("+returnstr+")");
							if(result.success){
								var cardinfo=result.cardinfo;
								if(cardinfo.type!="discount" && cardinfo.type!="cash"){
									layer.msg("付款期间只能使用【折扣券/代金券】",{icon:2,time:2000});
									return;
								}
								var orderfee=parseFloat($("#ppl_input_orderfee").val());
								var _discount=parseInt(cardinfo['discount']);
								if(parseInt(cardinfo['least_cost']) && parseInt(cardinfo['least_cost'])>str2num(orderfee)){
									layer.msg("此优惠券必须满<b>"+(parseInt(cardinfo['least_cost'])*0.01).toFixed(2)+"</b>元才能使用哦",{icon:2,time:2000});
									return;
								}
								if(cardinfo.type=="discount"){
									var coupon=orderfee*(100-_discount)*0.01;
									$("#ppl_input_discount").val(_discount+"%");
									$("#ppl_input_coupon").val(coupon.toFixed(2));
								}else{
									var coupon=_discount*0.01;
									$("#ppl_input_discount").val(parseInt((orderfee-coupon)/str2num(orderfee))+"%");
									$("#ppl_input_coupon").val(coupon.toFixed(2));
								}
								$(".counterCoupon").eq(2).addClass("isselect").siblings().removeClass("isselect");
								$("#ppl_dtype").attr("type",3);
								$("#ppl_dtype").text("优惠券");
								$("#pp_coupontype").val(3);
								$("#pp_couponno").val(cardno);
								fun_paycount();
							}else{
								layer.msg(result.msg,{icon:2,time:2000});
								return;
							}
							
						});
						return false;
					});
				},
				end:function(){
					$(".modal_inputbox").hide();
					$("#modal_inputboxbtn").unbind();

				}
			});
		break;
	}
}
function fun_paycount(){
	var isgrouppay=parseInt($("#isgrouppay").attr("isgrouppay"));
	var orderfee=str2num($("#ppl_input_orderfee").val());
	var coupon=str2num($("#ppl_input_coupon").val());
	var total=orderfee-coupon;
	$("#ppl_input_totalfee").val((total*0.01).toFixed(2));
	var paidfee=str2num($("#ppl_input_paidfee").val());
	var change=0;
	if(isgrouppay){
		var paidfee2=str2num($("#ppl_input_paidfee2").val());
		var tmep1=total-paidfee-paidfee2;
		if(tmep1<0)tmep1=0;
		change=paidfee2+paidfee-total;
		$("#ppl_input_change").val((change*0.01).toFixed(2));
	}else{
		var tmep1=total-paidfee;
		if(tmep1<0)tmep1=0;
		change=paidfee-total;
		$("#ppl_input_paidfee2").val((tmep1*0.01).toFixed(2))
		$("#ppl_input_change").val((change*0.01).toFixed(2));
	}
	$("#print_iframe").attr("src","jetsumprint://order?event=price&price="+total.toFixed(2));
}
function fun_ppRemove(type){
	/*清除优惠内容*/
	switch(type){
		case 2:
			var market=$("#ppl_dtype").attr("default");
			var orderfee=str2num($("#ppl_input_orderfee").val());
			if(market==""){
				$("#ppl_input_coupon").val('0');
				$("#ppl_input_discount").val("100%");
			}else{
				if(market.indexOf("%")>-1){
					market=parseInt(market.replace("%",""));
					var tempdis=100-market;
					var disount=(orderfee*tempdis*0.01).toFixed(2);
					$("#ppl_input_coupon").val(disount);
					$("#ppl_input_discount").val(parseInt(market)+"%");
				}else{
					var disount=parseInt(market);
					$("#ppl_input_coupon").val((disount*0.01).toFixed(2));
					$("#ppl_input_discount").val(parseInt(((orderfee-disount)/orderfee)*100)+"%");
				}
			}
			$(".counterCoupon").removeClass("isselect");
		break;
		case 3:
			$("#ppl_input_paidfee").val('0');
			$("#ppl_input_paidfee").attr("isselect",true);
			$("#ppl_input_paidfee2").removeAttr("isselect");
		break;
		case 4:
			$("#ppl_input_remark").val('');
		break;
		case 5:
			if(parseInt($("#isgrouppay").attr("isgrouppay"))){
				$("#ppl_input_paidfee2").val('0');
				$("#ppl_input_paidfee2").attr("isselect",true);
				$("#ppl_input_paidfee").removeAttr("isselect");
			}
		break;
	}
	fun_paycount();
}

function pp_searchTxtForm(){
	var keyword=$("#pp_searchTxt").val();
	var orderid=$("#ppl_orderid").val();
	if(!keyword){
		layer.msg("请输入卡号或者电话号码",{icon:2,time:2000},function(){$("#pp_searchTxt").focus()});
		return;
	}
	var index2=layer.load(1, {shade: [0.1,'#fff']});
	$.post("{php echo $this->createMobileUrl('index',array('op'=>'getmember'))}",{keyword:keyword,orderid:orderid},function(returnstr){
		layer.close(index2);
		console.log(returnstr);
		var result=eval("("+returnstr+")");
		if(result.success){
			var member=result.member;
			var cost=result.cost;
			$("#ppl_memberid").val(member.id);
			$("#ppl_txtheadimg").attr("src",member.headimgurl);
			$("#ppl_txtrealname").text(member.realname);
			$("#ppl_txtmobile").text(member.mobile);
			$("#ppl_txtcredit").text(member.credit2);
			$("#ppl_txtcash").text(member.cash2);
			$("#ppl_txtcost").text(cost);
			$("#ppl_txtbirdday").text(member.bird);
			$("#ppl_txtlevel").text(member.level);
			/*是否有会员满减优惠*/
			if(result.market){
				var market=result.market;
				$("#ppl_dtype").attr("type",1).attr("default",market.coupon).text("系统优惠");
				$("#pp_coupontype").attr("mid",market.mid).val(1);
				var orderfee=parseFloat($("#ppl_input_orderfee").val());
				var disount=fee2num(market.coupon);
				$("#ppl_input_coupon").val(disount);
				$("#ppl_input_discount").val(parseInt(((orderfee-disount)/orderfee)*100)+"%");
			}
			fun_paycount();
		}else{
			layer.msg(result.msg,{icon:2,time:2000});
			return;
		}
	});
}
function pp_searchTxtChargebtn(){
	if(!$("#ppl_memberid").val()){
		layer.msg("请先搜索会员",{icon:2,time:2000});
		return;
	}
	funExtend_charge($("#pp_searchTxt").val());
}
function fun_grouppay(obj){
	var isgrouppay=parseInt($(obj).attr("isgrouppay"));
	isgrouppay = isgrouppay ? 0 : 1;
	$(obj).attr("isgrouppay",isgrouppay);
	if(isgrouppay){
		$("#ppl_input_paidfee2").removeAttr("readonly");
		
		$(obj).addClass("ischeck").html('<div><i class="fa fa-ok-sign"></i></div>组合支付');
	}else{
		if(payTypeAry.length>1){
			var temp=payTypeAry[1];
			payTypeAry=[];
			fun_selectPaytype(temp);
		}
		$("#ppl_input_paidfee2").attr("readonly",true);
		$(obj).removeClass("ischeck").html('组合支付');
	}
	fun_paycount();
}
function fun_selectPaytype(type){
	var isgrouppay=parseInt($("#isgrouppay").attr("isgrouppay"));
	for(var i in payTypeAry){
		if(payTypeAry[i]==type)return;
	}
	payTypeAry.push(type);
	if(isgrouppay){
		if(payTypeAry.length>2)payTypeAry.splice(0,1);
	}else{
		payTypeAry=[type];
	}
	if(payTypeAry.join("")=="01" || payTypeAry.join("")=="10"){
		var temp=payTypeAry[0];
		payTypeAry=[];
		fun_selectPaytype(temp);
		layer.msg("微信和支付宝不能同时使用！",{icon:2,time:2000});
		return;
	}
	$(".pprbtn").removeClass("isselect").find("div").remove();
	$("#ppl_ptype").text("现金");
	$("#ppl_ptype2").text("待收");
	$("#ppl_paytype").val("-1");
	$("#ppl_paytype2").val("-1");
	
	for(var i=0;i<payTypeAry.length;i++){
		var txt=$(".pprbtn[paytype='"+payTypeAry[i]+"']").text();
		if(i==0){
			$("#ppl_ptype").text(txt);
			$("#ppl_paytype").val(payTypeAry[i]);
		}else{
			$("#ppl_ptype2").text(txt);
			$("#ppl_paytype2").val(payTypeAry[i]);
		}
		$(".pprbtn[paytype='"+payTypeAry[i]+"']").addClass("isselect").html('<div><i class="fa fa-ok"></i></div>'+txt);
	}
	fun_paycount();
}

function fun_payPost(){
	var orderid=$("#ppl_orderid").val();
	var orderfee=$("#ppl_input_orderfee").val();
	var teafee=$("#ppl_input_teafee").val();
	var discount=$("#ppl_input_discount").val();
	var coupon=$("#ppl_input_coupon").val();
	var totalfee=$("#ppl_input_totalfee").val();
	var paidfee=$("#ppl_input_paidfee").val();
	var paidfee2=$("#ppl_input_paidfee2").val();
	var change=$("#ppl_input_change").val();
	var remark=$("#ppl_input_remark").val();
	var paytype=parseInt($("#ppl_paytype").val());
	var paytype2=parseInt($("#ppl_paytype2").val());
	var memberid=$("#ppl_memberid").val();
	var code=$("#ppl_code").val();
	var qrcode=$("#ppl_qrcode").val();
	var paycode=$("#ppl_paycode").val();
	var orderid=$("#ppl_orderid").val();
	var coupontype=$("#pp_coupontype").val();
	var couponno=$("#pp_couponno").val();
	var data={
		"orderid":orderid,
		"orderfee":orderfee,
		"teafee":teafee,
		"discount":discount,
		"coupon":coupon,
		"totalfee":totalfee,
		"paidfee":paidfee,
		"paidfee2":paidfee2,
		"change":change,
		"remark":remark,
		"paytype":paytype,
		"paytype2":paytype2,
		"memberid":memberid,
		"code":code,
		"qrcode":qrcode,
		"paycode":paycode,
		"coupontype":coupontype,
		"couponno":couponno,
		"marketing":parseInt(coupontype)==1 ? $("#pp_coupontype").attr("mid") : 0,
	};
	if(parseInt($("#isgrouppay").attr("isgrouppay"))){
		if(str2num(paidfee)==0 || str2num(paidfee2)==0){
			layer.msg("组合支付必须同时有支付金额。",{icon:2,time:2000});
			return;
		}
		if(str2num(paidfee)+str2num(paidfee2)<str2num(totalfee)){
			layer.msg("付款金额不足",{icon:2,time:2000});
			return;
		}
        if(str2num(paidfee)+str2num(paidfee2)>str2num(totalfee)){
            if(parseInt(paytype)!=2 && parseInt(paytype2)!=2){
                layer.msg("支付金额不能大于需要支付的金额",{icon:2,time:2000});
                return;
            }
        }
	}else{
		if(str2num(paidfee)<str2num(totalfee)){
			layer.msg("付款金额不足",{icon:2,time:2000});
			return;
		}
	}
    if(paytype!=2 && paytype2!=2 && str2num(change)>0){
        layer.msg("总付款金额不能大于结算金额",{icon:2,time:2000});
        return;
    }
	if((paytype==0 || paytype==1) && !qrcode){
		fun_payneedInput(paytype);
		return;
	}
	if((paytype==3 || paytype2==3) && !code){
		fun_payneedInput(3);
		return;
	}
	if(paytype==4 || paytype2==4){
		if(!memberid){
			fun_payneedInput(4);
			return;
		}
		if(parseInt("{$cfg['ispaycode']}") && !paycode){
			fun_payneedInput(99);
			return;
		}
		var needpay= paytype ==4 ? str2num($("#ppl_input_paidfee").val()):str2num($("#ppl_input_paidfee2").val());
		var membercash=str2num($("#ppl_txtcash").val());
		if(needpay>membercash){
			layer.msg("余额不足，请先充值",{icon:2,time:2000});
			return;
		}
	}
	if((paytype2==0 || paytype2==1) && !qrcode){
		fun_payneedInput(paytype2);
		return;
	}
	var index2=layer.load(1, {shade: [0.1,'#fff']});
	$.post("{php echo $this->createMobileUrl('index',array('op'=>'payall'))}",data,function(returnstr){
		layer.close(index2);
		console.log(returnstr);
		var result=eval("("+returnstr+")");
		if(result.success){
			if(result.paywait){
				var index3=layer.msg('等待用户输入支付密码',{icon:16,shade:0.1,time:35000});
				setTimeout(function(){fun_payneedPass(orderid,index3,1)},5000);
				return;
			}
			fun_paysuccess(orderid);
		}else{
			$("#ppl_qrcode").val("");
            $("#ppl_paycode").val("");
			layer.msg(result.msg,{icon:2,time:2000});
			return;
		}
		
	});
}
function fun_payneedInput(type){
	switch(type){
		case 3:
			layer.open({
				type:1,
				title:"使用银行卡支付",
				shade: [0.1,'#fff'],
				area:'400px',
				skin: 'layui-layer-rim',
				content:$(".modal_inputbox").show(),
				success: function(layero, index){

					$("#modal_inputboximg").hide();
					$("#modal_inputboximg .help-block").text("请使用POS机收款后，再将银行卡后4位输入到上方");
					$("#modal_inputbox").val('').attr("placeholder","请输入银行卡后4位");
					$("#modal_inputbox").focus();
					$("#modal_inputboxbtn").bind("click",function(){
						layer.close(index);
						$("#ppl_code").val($("#modal_inputbox").val());
						fun_payPost();
						return false;
					});
				},
				end:function(){
					$(".modal_inputbox").hide();
					$("#modal_inputboxbtn").unbind();
                    
				}
			});
		break;
		case 4:
			if(!$("#ppl_memberid").val()){
				layer.msg("请先选择会员卡",{icon:2,time:2000});
				return;
			}
			var membercash=str2num($("#ppl_txtcash").text());
			var total=str2num($("#ppl_input_totalfee").val());
			if(membercash<total){
				layer.msg("余额不足，请先充值",{icon:2,time:2000});
				return;
			}
			fun_payPost();
		break;
		case 0:
			layer.open({
				type:1,
				title:"使用微信支付",
				shade: [0.1,'#fff'],
				area:['300px','480px'],
				skin: 'layui-layer-rim',
				content:$(".modal_inputbox").show(),
				success: function(layero, index){

					$("#modal_inputboximg").show();
					$("#modal_inputboximg .help-block").text("请扫描客户的付款二维码");
					$("#modal_inputbox").val('').attr("placeholder","请扫描客户的付款二维码");
					$("#modal_inputbox").focus();
					$("#modal_inputboxbtn").bind("click",function(){
						layer.close(index);
						$("#ppl_qrcode").val($("#modal_inputbox").val());
						fun_payPost();
						return false;
					});
				},
				end:function(){
					$(".modal_inputbox").hide();
					$("#modal_inputboxbtn").unbind();

				}
			});
		break;
		case 1:
			layer.open({
				type:1,
				title:"使用支付宝支付",
				shade: [0.1,'#fff'],
				area:['300px','480px'],
				skin: 'layui-layer-rim',
				content:$(".modal_inputbox").show(),
				success: function(layero, index){

					$("#modal_inputboximg").show();
					$("#modal_inputboximg .help-block").text("请扫描客户的付款二维码");
					$("#modal_inputbox").val('').attr("placeholder","请扫描客户的付款二维码");
					$("#modal_inputbox").focus();
					$("#modal_inputboxbtn").bind("click",function(){
						layer.close(index);
						$("#ppl_qrcode").val($("#modal_inputbox").val());
						fun_payPost();
						return false;
					});
				},
				end:function(){
					$(".modal_inputbox").hide();
					$("#modal_inputboxbtn").unbind();

				}
			});
		break;
		case 99:
			var index2=layer.load(1, {shade: [0.1,'#fff']});
			var memberid=$("#ppl_memberid").val();
			var orderid=$("#ppl_orderid").val();
			$.post("{php echo $this->createMobileUrl('index',array('op'=>'sendmemberpaycode'))}",{memberid:memberid,orderid:orderid},function(returnstr){
				layer.close(index2);
				console.log(returnstr);
				var result=eval("("+returnstr+")");
				if(result.success){
					if(result.need){
						layer.open({
							type:1,
							title:"请输入会员卡支付验证码",
							shade: [0.1,'#fff'],
							area:'400px',
							skin: 'layui-layer-rim',
							content:$(".modal_inputbox").show(),
							success: function(layero, index){

								$("#modal_inputboximg").hide();
								$("#modal_inputboximg .help-block").text("请输入会员卡支付验证码");
								$("#modal_inputbox").val('').attr("placeholder","请输入会员卡支付验证码");
								$("#modal_inputbox").focus();
								$("#modal_inputboxbtn").bind("click",function(){
									layer.close(index);
									$("#ppl_paycode").val($("#modal_inputbox").val());
									fun_payPost();
									return false;
								});
							},
							end:function(){
								$(".modal_inputbox").hide();
								$("#modal_inputboxbtn").unbind();

							}
						});
					}else {
						$("#ppl_paycode").val(result.code);
						fun_payPost();
					}

				}else{
					layer.msg(result.msg,{icon:2,time:2000});
					return;
				}
			});

		break;
	}
}
function fun_payneedPass(orderid,indexs){
	var timers=1;
	if(arguments.length>2)timers=parseInt(arguments[2])+1;
	if(timers>=7){
		layer.close(indexs);
		layer.msg("支付时间超时",{icon:2,time:2000});
		return;
	}
	$.post("{php echo $this->createMobileUrl('index',array('op'=>'paywaitpassword'))}",{orderid:orderid},function(returnstr){
		console.log(returnstr);
		var result=eval("("+returnstr+")");
		if(result.success){
			if(result.paywait){
				setTimeout(function(){fun_payneedPass(orderid,indexs,timers);},5000);
				return;
			}
			fun_paysuccess(orderid);
		}else{
			layer.close(indexs);
			layer.msg(result.msg,{icon:2,time:2000});
			return;
		}
	});
}
function fun_paysuccess(orderid){
	layer.closeAll();
	layer.msg("收款成功",{icon:1,time:2000});
	var printpage=0;
	if($("#isprintform .layui-form-checked").size())printpage=1;
	var index2=layer.load(1,{shade: [0.1,'#fff']});
	$.post("{php echo $this->createMobileUrl('index',array('op'=>'paysuccess'))}",{orderid:orderid},function(returnstr){
		layer.close(index2);
		var result=eval("("+returnstr+")");
		if(result.success){
			resetFormInput();
			if(printpage)fun_print(1,orderid);
		}else{
			layer.msg(result.msg,{icon:2,time:2000});
			return;
		}
		//---收款完成---//
	});
}
    function fun_inputAll(){
        if($("#isgrouppay").attr("isgrouppay")=="1"){
            var total_fee=str2num($("#ppl_input_totalfee").val());
            var fee1=str2num($("#ppl_input_paidfee").val());
            var fee2=str2num($("#ppl_input_paidfee2").val());
            if(total_fee-fee1-fee2==0)return;
            if(fee2==0){
                $("#ppl_input_paidfee2").val(fee2num(total_fee-fee1));
            }else if(fee1==0){
                $("#ppl_input_paidfee").val(fee2num(total_fee-fee2));
            }
        }else{
            var total_fee=$("#ppl_input_totalfee").val();
            $("#ppl_input_paidfee").val(total_fee);
        }
        fun_paycount();
    }
</script>